<template>
  <a-modal :open="open" width="600px" height="800" title="过敏信息" centered :scroll="{ y: 500 }" @cancel="onCancel" @ok="onOk">
    <div class="h-[560px] overflow-y-scroll">
      <BaseTable :columns="columns" :data-source="tableData" :loading="loading" :pagination="null">
        <template #bodyCell="{ column, record, index }">
          <template v-if="column.dataIndex === 'NO'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'gms'">
            <a-radio-group v-model:value="record.gms">
              <a-radio value="未查">未查</a-radio>
              <a-radio value="无">无</a-radio>
              <a-radio value="有">有</a-radio>
            </a-radio-group>
          </template>
        </template>
      </BaseTable>
    </div>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { post } from '@/utils/request'

const tableData = ref([])
const loading = ref(false)
const props = defineProps({
  open: Boolean,
  rowData: {
    type: String,
    default: ''
  }
})

const emit = defineEmits(['update:open', 'close', 'success'])

const columns = ref([
  {
    title: '序号',
    dataIndex: 'NO'
  },
  {
    title: '药品',
    dataIndex: 'dictItemName'
  },
  {
    title: '过敏',
    width: 200,
    dataIndex: 'gms'
  }
])

const getData = async () => {
  loading.value = true
  const { code, data } = await post('/operation/opex/getDictCommonItemList', {
    dictCommonCode: 'DT00032',
    status: 1
  })
  loading.value = false
  if (code === 0) {
    tableData.value = data.map((item) => {
      if (props.rowData) {
        props.rowData?.split(',').forEach((el) => {
          if (el.split(':')[0] === item.dictItemName) {
            item.gms = '有'
          }
        })
      } else {
        item.gms = '未查'
      }

      return item
    })
  }
}
const onCancel = () => {
  emit('update:open', false)
  emit('close')
}
const onOk = () => {
  emit('update:open', false)
  emit('success', tableData.value)
}

watch(
  () => props.open,
  () => {
    getData()
  }
)
</script>
